<template>

  <basic-container>

    <avue-form :option="option" v-model="form"  @submit="handleSubmit"  ref ="formRem">

      <template #tableName-type="{item,value,label}">

        <span>{{ item.value }}[{{item.label}}]</span>
      </template>
    </avue-form>

  </basic-container>
</template>

<script>
import BasicContainer from "@/components/basic-container/main.vue";
import {baseUrl} from "../../../config/env";
import baseService from "../../../crud/baseService";

export default {
  name: "chooseTable",
  components: {BasicContainer},
  data() {

    return {
      form: {
        datasourceId: '',
        tableName: '',

      },
      option: {
        column: [{
          label: '数据源',
          prop: 'datasourceId',
          type: 'select',

          dicUrl: baseUrl + "/generator/gDatasource/datasourceList",
          cascader: ['tableName'],
          rules: [
            {
              required: true,
              message: "请输入数据源",
              trigger: "blur"
            }

          ]

        },
          {
            label: '数据源',
            prop: 'tableName',
            type: 'select',

            dicUrl: baseUrl + `/generator/gTableInfo/listTableByDatabaseId?datasourceId={{datasourceId}}`,
            rules: [
              {
                required: true,
                message: "请输入数据源",
                trigger: "blur"
              }

            ],
            typeformat(item, label, value) {
              return `${item[value]}-[${item[label]}]`
            },

          }

        ]
      }
    }
  },
  created() {
    console.log("chooseTable")
  }
  ,
  methods: {
    init() {
      console.log("init")
    },
    handleSubmit (form, done) {

      // setTimeout(() => {
      //
      //   this.$message.success('3秒后关闭表单')
      // }, 1000)
      // // setTimeout(() => {
      // //   done()
      // // }, 3000)



      setTimeout(() => {
        done()
        this.$emit("updateDialogVisible",false)
        baseService.postJsonData("/generator/gTableInfo/loadTable", form).then(res => {
          console.log(res)

        });
      }, 1000)

    }
  }
}
</script>

<style scoped>


</style>
